LazyScrollDir
By Paul S. McCarthy and Eric Sunshine
Copyright ã1995,1996 by Paul S. McCarthy and Eric Sunshine
February 9, 1996

Overview

This program demonstrates the use of MiscTableScroll object in lazy mode by acting as a simple directory browser.  Basic operations such as open, delete, and change directory can be performed on the listed files and directories.

Notable Features

Lazy Mode
This program illustrates how to use a lazy mode MiscTableScroll.  In lazy mode the data-delegate is responsible for supplying the cells that the MiscTableScroll will display.  In this example, the data-delegate also supplies information (such as stringValue, intValue, tag, etc.) during sorting as a speed optimization.

This program allocates a single cell for each column.  When the MiscTableScroll requests a cell for some column and row, the data-delegate takes the cell it allocated for that column, fills it with information from that row, and returns it.  As a side-effect of this, time-consuming operations like fetching a file's icon can be delayed until it is actually needed.  Likewise retrieval of group and owner names from NetInfo (also time-consuming) is delayed until display or sort time.

This contrasts sharply with eager mode, in which all cells are created and filled immediately.  Lazy mode is useful for exceptionally large data sets or data sets for which data retrieval is very time-consuming.  Eager mode, however, is usually easier to program.

Color
The example shows how to use color with the MiscTableScroll.  Color swatches can be dragged from the Color Panel and dropped onto the browser window.  The background of the MiscTableScroll is set to the color of the dropped swatch.

When the highlight directories switch is toggled on the rows for directories are highlighted in a color independent of the MiscTableScroll.

Font
When the MiscTableScroll is first-responder, the Font Panel can be used to change its font.

Users Preferences
This program demonstrates how to save and restore the user's column order and width preferences.  Additionally, all other user preferences -- font, color, switch settings, and window size -- are also saved and restored.

Icon Display
One column in the browser displays the file's icon.  This demonstrates the use of icon columns in addition to text columns.

Sorting
A switch on the browser window controls whether or not rows are automatically sorted as columns are rearranged via dragging.  This demonstrates the very powerful built-in sorting capability of MiscTableScroll.  Sorting can be fine-tuned right in the nib file by adjusting the criteria on a column-by-column basis.  For instance, columns may contribute stringValue, title, intValue, tag, etc. to the row-wise comparisons.

Name Caching
NetInfo is notoriously slow.  Translation of user and group numbers into their text equivalents is sped up by caching the results of calls to getpwuid and getgrgid (both of which ultimately consult NetInfo).